<!-- 其他出库单 -->
<template>
  <div class="basic_info">
    <div class="info_operation_btn">
      <div class="btn_left">
        <el-button :type="newBtnStatus ? 'primary' : ''" @click="onNewOrder"
          >新单(N)</el-button
        >
        <el-button
          v-if="buttonsPermissions.LuRu"
          :disabled="saveBtnStatus"
          :class="saveBtnStatus ? 'disabled_button' : ''"
          :type="orderStatus == 66 ? 'primary' : ''"
          @click="onSubmit"
          >保存(S)</el-button
        >
        <el-button v-else class="disabled_button" disabled>保存(S)</el-button>
        <el-button
          v-if="buttonsPermissions.ShenHe"
          :disabled="auditBtnStatus"
          :class="auditBtnStatus ? 'disabled_button' : ''"
          :type="orderStatus == 0 ? 'primary' : ''"
          @click="onToExamine"
          >审核(A)</el-button
        >
        <el-button v-else class="disabled_button" disabled>审核(A)</el-button>
        <!-- 操作按钮 -->
        <el-select v-model="operationValue">
          <el-option
            @click.native="operationSelect(item.value)"
            v-for="item in operationData"
            :key="item.value"
            :label="item.value"
            :value="item.value"
            :disabled="item.disabled"
            :style="item.disabled ? 'pointer-events: none' : ''"
          ></el-option>
        </el-select>
        <!-- 调单 -->
        <el-select
          v-model="exchangeValue"
          @change="exchangeSelect(exchangeValue)"
          :disabled="saveBtnStatus"
        >
          <el-option
            v-for="item in exchangeOptions"
            :key="item"
            :label="item"
            :value="item"
          ></el-option>
        </el-select>
        <!-- 导入导出 -->
        <el-button
          :disabled="!buttonsPermissions.DaoRu || (orderStatus != 66 && orderStatus != 0)"
          :class="
            !buttonsPermissions.DaoRu || (orderStatus != 66 && orderStatus != 0)
              ? 'disabled_button'
              : ''
          "
          @click="importExcel"
          >导入</el-button
        >
        <!-- <el-select v-model="importValue">
          <el-option
            v-if="buttonsPermissions.DaoRu"
            :disabled="orderStatus != 66 && orderStatus != 0"
            label="导入"
            value="导入"
            @click.native="importExcel"
            :style="orderStatus != 66 && orderStatus != 0 ? 'pointer-events: none' : ''"
          ></el-option>
          <el-option v-else disabled label="导入" value="导入" style="pointer-events: none"></el-option>
          <el-option
            v-if="buttonsPermissions.DaoChu"
            :disabled="orderStatus == 66"
            label="导出"
            value="导出"
            @click.native="exportExcel"
            :style="orderStatus == 66 ? 'pointer-events: none' : ''"
          ></el-option>
          <el-option v-else disabled label="导出" value="导出" style="pointer-events: none"></el-option>
        </el-select>-->
        <el-button
          v-if="buttonsPermissions.DaYin"
          :disabled="orderStatus == 66"
          :class="orderStatus == 66 ? 'disabled_button' : ''"
          @click="handleShortcutKeyPrint"
          >打印(P)</el-button
        >
        <el-button v-else class="disabled_button" disabled>打印</el-button>
        <el-button @click="onShare" v-if="buttonsPermissions.FenXiang">分享</el-button>
        <el-button v-else class="disabled_button" disabled>分享</el-button>
        <el-button @click="onCheckBill">单据核对</el-button>
        <!-- 审核状态 -->
        <img
          v-if="orderStatus == 5"
          style="width: 50px; height: 38px; margin-right: 10px"
          src="@/assets/shenhe.png"
        />
        <img
          v-else-if="orderStatus == 10"
          style="width: 57px; height: 43px; margin-right: 10px"
          src="@/assets/zuofei.png"
        />
        <img
          v-else-if="orderStatus == 20"
          style="width: 57px; height: 24px; margin-right: 10px"
          src="@/assets/hongchong.png"
        />
        <span v-else style="color: #1993fb; margin-right: 10px">{{
          queryData.orderStatus_dictText || "未保存"
        }}</span>
        <!-- <span style="color: #1993fb">{{ queryData.orderStatus_dictText || '未保存' }}</span> -->
      </div>
      <div class="btn_right">
        <div
          style="width: 75px; display: flex; justify-content: space-between"
          ref="guide8"
        >
          <el-tooltip effect="dark" content="上一条" :enterable="false" placement="top">
            <el-button
              @click="onUpper"
              class="arrow_btn"
              icon="el-icon-arrow-left"
              :loading="upperLoading"
            ></el-button>
          </el-tooltip>
          <el-tooltip effect="dark" content="下一条" :enterable="false" placement="top">
            <el-button
              @click="onLower"
              class="arrow_btn"
              icon="el-icon-arrow-right"
              :loading="lowerLoading"
            ></el-button>
          </el-tooltip>
        </div>
        <div class="search_order">
          <span>单据编号：</span>
          <div class="order_number">{{ queryData.orderNumber }}</div>
        </div>
        <div class="bill_mask_back_view">
          <div v-if="maskViewStatus" class="bill_mask_view"></div>
          <el-checkbox
            :disabled="!supplementPermissions"
            v-model="queryData.isSupplement"
            @change="supplementChange"
            >补单</el-checkbox
          >
        </div>
      </div>
    </div>
    <div class="info_content_div">
      <div class="div_table">
        <div class="div_screen">
          <div class="custom_left bill_mask_back_view" style="flex-wrap: wrap">
            <div v-if="maskViewStatus" class="bill_mask_view"></div>
            <!-- 供应商 -->
            <div class="custom_item">
              <div class="custom_star">
                <div class="custom_label" style="width: auto; min-width: 40px">客户</div>
                <span class="star">*</span>
              </div>
              <div class="custom_select_head">
                <el-tooltip
                  :disabled="companyName.length <= 6"
                  effect="dark"
                  :content="companyName"
                  :enterable="false"
                  placement="bottom-start"
                >
                  <el-select
                    v-model="queryData.xghCompanyId"
                    style="width: 100%"
                    @change="onChangeCompany"
                    filterable
                    ref="deptSelect"
                    @visible-change="(value) => handleFilterMethod('', 'companyName')"
                    :filter-method="(value) => handleFilterMethod(value, 'companyName')"
                    @keydown.native.enter="handleCompanyEnter"
                  >
                    <el-option
                      v-for="item in gysOptions"
                      :key="item.id"
                      :label="item.companyName"
                      :value="item.id"
                      :disabled="item.status == '1'"
                    ></el-option>
                    <el-option v-if="companyAdd" key label value>
                      <div class="custom_add" @click.stop="onShowSupplierAdd">
                        <i class="el-icon-plus"></i>
                        <span>新增</span>
                      </div>
                    </el-option>
                  </el-select>
                </el-tooltip>
                <div class="custom_more">
                  <i class="el-icon-more" @click.stop="onShowSupplier"></i>
                </div>
              </div>
            </div>
            <!-- 出货仓库 -->
            <div class="custom_item">
              <div class="custom_star">
                <span class="custom_label" style="width: auto; min-width: 50px"
                  >出货仓库</span
                >
                <span class="star">*</span>
              </div>
              <div class="custom_select_head">
                <el-select
                  v-model="queryData.xghOutStorehouseId"
                  style="width: 100%; height: 30px"
                  @change="onChangeCk"
                  filterable
                  ref="deptSelect"
                  @visible-change="(value) => handleFilterMethod('', 'storehouseName')"
                  :filter-method="(value) => handleFilterMethod(value, 'storehouseName')"
                  @keydown.native.enter="handleStoreEnter"
                >
                  <el-option
                    v-for="item in ckOptions"
                    :key="item.id"
                    :label="item.storehouseName"
                    :value="item.id"
                  ></el-option>
                  <el-option v-if="storeAdd" key label value>
                    <div class="custom_add" @click.stop="onShowWhAdd">
                      <i class="el-icon-plus"></i>
                      <span>新增</span>
                    </div>
                  </el-option>
                </el-select>
              </div>
            </div>
            <!-- 经手人 -->
            <div class="custom_item">
              <div class="custom_star">
                <div class="custom_label" style="width: auto; min-width: 40px">
                  经手人
                </div>
              </div>
              <div class="custom_select_head">
                <el-select
                  v-model="queryData.sysUserId"
                  style="width: 100%"
                  filterable
                  ref="deptSelect"
                  @visible-change="(value) => handleFilterMethod('', 'realname')"
                  :filter-method="(value) => handleFilterMethod(value, 'realname')"
                  @keydown.native.enter="handleUserEnter"
                >
                  <el-option
                    v-for="item in jsrOptions"
                    :key="item.id"
                    :label="item.realname"
                    :value="item.id"
                  ></el-option>
                  <el-option key label value>
                    <div class="custom_add" @click.stop="onShowStaffAdd">
                      <i class="el-icon-plus"></i>
                      <span>新增</span>
                    </div>
                  </el-option>
                </el-select>
              </div>
            </div>
            <!-- 出库类型 -->
            <div class="custom_item">
              <div class="custom_star">
                <span class="custom_label" style="width: auto; min-width: 50px"
                  >出库类型</span
                >
                <span class="star">*</span>
              </div>
              <div class="custom_select_head">
                <el-select
                  v-model="queryData.xghOutType"
                  style="width: 100%"
                  filterable
                  ref="xghOutTypeSelect"
                  @keydown.native.enter="handleOutTypeEnter"
                >
                  <el-option
                    v-for="item in cklxOptions"
                    :key="item.id"
                    :label="item.description"
                    :value="item.id"
                  ></el-option>
                  <el-option key label value>
                    <div class="custom_add" @click.stop="onShowOutTypeAdd">
                      <i class="el-icon-plus"></i>
                      <span>新增</span>
                    </div>
                  </el-option>
                </el-select>
              </div>
            </div>
            <!-- 出库日期 -->
            <div class="custom_item">
              <div class="custom_star">
                <div class="custom_label" style="width: auto; min-width: 50px">
                  出库日期
                </div>
              </div>
              <div class="custom_select_head">
                <el-date-picker
                  :disabled="queryData.isSupplement ? false : true"
                  v-model="queryData.outTime"
                  value-format="yyyy-MM-dd"
                  style="height: 30px"
                ></el-date-picker>
              </div>
            </div>
            <!-- 出库部门 -->
            <div class="custom_item">
              <div class="custom_star">
                <div class="custom_label" style="width: auto; min-width: 50px">
                  出库部门
                </div>
              </div>
              <div class="custom_select_head">
                <el-select
                  v-model="queryData.xghOutDeptId"
                  style="width: 100%"
                  filterable
                  ref="xghOutDeptSelect"
                >
                  <el-option
                    v-for="item in deptOptions"
                    :key="item.id"
                    :label="item.deptName"
                    :value="item.id"
                  ></el-option>
                </el-select>
              </div>
            </div>
          </div>
          <div class="screen_right">
            <i @click="onShowColumn()" class="set_up el-icon-s-tools"></i>
          </div>
        </div>
        <div class="table_content">
          <div>
            <NewTable
              ref="newTableRef"
              :TableConfig="TableConfig"
              :StorehouseList="ckOptions"
              :billDisabled="maskViewStatus"
              :companyId="queryData.xghCompanyId"
              :storehouseId="queryData.xghOutStorehouseId"
              :discountRate="queryData.orderRebate"
              :taxRate="taxRate"
              orderName="salesBill"
              accessType="out"
              @onHandleSpData="onHandleSpData"
              @onHandleUnit="onHandleUnit"
              @onHandleAllPrice="onHandleAllPrice"
            ></NewTable>
          </div>
        </div>
        <div class="bottom_view" style="display: flex">
          <div style="flex: 1">
            <a-row :gutter="24" style="padding: 20px 10px; height: 70px">
              <a-col :span="12">
                <div class="bill_mask_back_view">
                  <div v-if="maskViewStatus" class="bill_mask_view"></div>
                  <div class="table_item">
                    <div>备注：</div>
                    <el-input
                      v-model="queryData.remark"
                      v-if="!maskViewStatus || !queryData.remark"
                    ></el-input>
                    <el-tooltip v-else :content="queryData.remark" placement="top">
                      <el-input
                        v-model="queryData.remark"
                        :disabled="maskViewStatus"
                        style="z-index: 11"
                      ></el-input>
                    </el-tooltip>
                  </div>
                </div>
              </a-col>
              <a-col :span="12">
                <div class="table_item">
                  <div>附记：</div>
                  <el-tooltip
                    :content="queryData.postscript"
                    placement="top"
                    :disabled="!queryData.postscript"
                  >
                    <el-input
                      v-model="queryData.postscript"
                      @blur="updatePostScript()"
                    ></el-input>
                  </el-tooltip>
                </div>
              </a-col>
            </a-row>
          </div>
          <div
            style="
              width: 300px;
              display: flex;
              align-items: center;
              justify-content: flex-end;
              height: 100%;
              margin-right: 10px;
            "
          >
            <div class="table_item">
              <div>制单人：</div>
              <span>{{ queryData.createName }}</span>
            </div>
            <div class="table_item">
              <div style="width: auto; margin-left: 30px">制单日期：</div>
              <span>{{ formatCreateOrderDate }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 列配置弹框 -->
    <CConfiguration
      ref="setColumnRef"
      :columnDataArr="getColumnList"
      :defaultColumnDataArr="defaultColumnData"
      :orderType="pageName"
      @onSaveColumn="onSaveColumn"
    ></CConfiguration>
    <!-- 选择客户弹框 -->
    <DialogSupplier
      ref="supplierRef"
      @onSelectSupplier="onSelectSupplier"
    ></DialogSupplier>
    <!-- 新增客户弹框 -->
    <DialogSupplierAdd
      ref="supplierAddRef"
      @dialogVisibleClose="onCloseAddSupplier"
      @onAddSubmit="onAddSupplier"
    ></DialogSupplierAdd>
    <!-- 新增仓库弹框 -->
    <DialogWarehouseAdd
      ref="warehouseAddRef"
      :newData="newWhData"
      @onAddSubmit="onAddWh"
      @handleClose="onCloseAddWh"
    ></DialogWarehouseAdd>
    <!-- 新增员工弹框 -->
    <DialogStaffAdd
      ref="staffAddRef"
      @dialogVisibleClose="onCloseAddStaff"
      @onAddSubmit="onAddStaff"
    ></DialogStaffAdd>
    <!-- 提醒弹框 -->
    <PopupReminder
      ref="reminderRef"
      :tipsData="tipsData"
      @onConfirm="onYes"
      @onCancel="onCancel"
    ></PopupReminder>
    <!-- 成功弹框 -->
    <PopupSuccess
      ref="successRef"
      :tipsData="tipsData"
      @onConfirm="onOptionSuccess"
    ></PopupSuccess>
    <!-- 操作日志 -->
    <DialogOperationLog :logTitle="logTitle" ref="operationLogRef"></DialogOperationLog>
    <!-- 反审支付弹框 -->
    <PopupDeApproval ref="deApprovalRef" @onConfirmFree="onUnToExamine"></PopupDeApproval>
    <!-- 导入 -->
    <DialogImport
      ref="daoru"
      :titles="TableConfig.columnData"
      :storehouseId="queryData.xghOutStorehouseId"
      url="/xghSaleStorehouseOrder/xghSaleStorehouseOrder/otherImportExcel"
      @importData="importData"
      @downloadTemplate="exportExcel"
    ></DialogImport>
    <!-- 单价为零时的弹窗 -->
    <DialogPriceZero
      :showPriceZeroDialog="showPriceZeroDialog"
      :priceZeroGoodsData="priceZeroGoodsData"
      @priceZeroCallback="priceZeroCallback"
    ></DialogPriceZero>
    <!-- 销售价低于成本价时的弹窗 -->
    <DialogPriceBelow
      :showPriceZeroDialog="showPriceBelowDialog"
      :priceZeroGoodsData="priceBelowGoodsData"
      @priceZeroCallback="priceBelowCallback"
    ></DialogPriceBelow>
    <!-- 负库存的弹窗 -->
    <DialogNegativeInventory
      :showPriceZeroDialog="showNegativeInventoryDialog"
      :priceZeroGoodsData="negativeInventoryData"
      @priceZeroCallback="negativeInventoryCallBack"
    ></DialogNegativeInventory>
    <!-- 单据状态变更提示 -->
    <dialogSimplePrompt ref="simplePrompt" @onSure="hongchongSure"></dialogSimplePrompt>
    <!-- 单据核对 -->
    <dialogBillContrast ref="billContrast"></dialogBillContrast>
    <!-- 调单 -->
    <dialogTransferBill
      ref="transferBill"
      @onSelectBill="transferBillCallback"
    ></dialogTransferBill>
    <el-dialog
      :title="dialogTitle"
      :visible.sync="dialogVisible"
      width="460px"
      :append-to-body="true"
    >
      <other-type
        @cancel="dialogVisible = false"
        @onUpdataType="onUpdataType"
        :inOrOut="inOrOut"
        @onSelectData="onSelectData"
      ></other-type>
    </el-dialog>
    <!-- 打印 -->
    <dialog-print ref="print"></dialog-print>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import dialogSimplePrompt from "../components/dialogSimplePrompt"; //单据操作提示
import dialogBillContrast from "../components/dialogBillContrast"; //单据核对
import dialogTransferBill from "../components/dialogTransferBill"; //调单
import CConfiguration from "@/components/c_column/columnConfiguration1";
import DialogSupplier from "../components/dialogSupplier";
import DialogSupplierAdd from "../components/dialogSupplierAdd";
import PopupReminder from "../components/popupReminder";
import PopupSuccess from "../components/popupSuccess";
import DialogOperationLog from "../components/dialogOperationLog";
import PopupDeApproval from "../components/popupDeApproval";
import OtherType from "../components/dialogOtherType";
import { ACCESS_TOKEN, TENANT_ID, ACCOUNT_BOOK } from "@/store/mutation-types";
import Vue from "vue";
/*商品列表 */
import NewTable from "@/components/c_table/newTable";
/*新增仓库 */
import DialogWarehouseAdd from "../components/dialogWarehouseAdd";
/*新增经手人 */
import DialogStaffAdd from "../components/dialogStaffAdd";
/*导入弹窗 */
import DialogImport from "@/components/c_Import/index1";
/**单价为0时的弹窗 */
import DialogPriceZero from "../components/dialogPriceZero";
/**销售价低于成本价时的弹窗 */
import DialogPriceBelow from "../components/dialogPriceBelow";
/**负库存的弹窗 */
import DialogNegativeInventory from "../components/dialogNegativeInventory";
/**打印 */
import dialogPrint from "../components/dialogPrintStock.vue";
import { getAction, postAction, downPostFile, putAction } from "@/api/manage";
// 导入调用处理权限数据方法
import {
  handlePermissions,
  handleOtherPerms,
  sysConfig,
  getSystemParamsByName,
  formatFour,
  formatMoney,
  formatPrice,
  formatNumber,
  delcommafy,
  handleArrayToObject,
  handleObjectToArray,
  formatHundredMillionPrice,
  accMul,
  getAttributeOrderInfoRequest
} from "@/utils/index";
import { JeecgListMixin } from "@/mixins/JeecgListMixin";
export default {
  name: "otherDelivary",
  mixins: [JeecgListMixin],
  components: {
    CConfiguration,
    DialogSupplier,
    DialogSupplierAdd,
    PopupReminder,
    PopupSuccess,
    DialogOperationLog,
    PopupDeApproval,
    NewTable,
    DialogWarehouseAdd,
    DialogStaffAdd,
    DialogImport,
    DialogPriceZero,
    dialogSimplePrompt,
    dialogBillContrast,
    dialogTransferBill,
    DialogPriceBelow,
    DialogNegativeInventory,
    OtherType,
    dialogPrint,
  },
  computed: {
    ...mapGetters(["isSupplementOrder"]),
    //orderStatus 订单状态：新单66、0待审核、5审核通过、10作废、15反审、20红冲、25终止、30完成
    newBtnStatus() {
      return (
        this.orderStatus == 5 ||
        this.orderStatus == 10 ||
        this.orderStatus == 20 ||
        this.orderStatus == 30
      );
    },
    saveBtnStatus() {
      return (
        this.orderStatus == 5 ||
        this.orderStatus == 10 ||
        this.orderStatus == 20 ||
        this.orderStatus == 30
      );
    },
    auditBtnStatus() {
      return (
        this.orderStatus == 66 ||
        this.orderStatus == 5 ||
        this.orderStatus == 10 ||
        this.orderStatus == 20 ||
        this.orderStatus == 25 ||
        this.orderStatus == 30
      );
    },
    maskViewStatus() {
      return this.orderStatus != 66 && this.orderStatus != 0;
    },
    getColumnList() {
      return handleObjectToArray(this.TableConfig.columnData);
    },
    formatCreateOrderDate() {
      let date = this.queryData.createOrderDate;
      if (date.length > 10) {
        date = date.slice(0, 10);
      }
      return date;
    },
    storeAdd() {
      return handlePermissions("仓库信息").LuRu;
    },
    buttonsPermissions() {
      return handlePermissions("其他出库单");
    },
    companyAdd() {
      return handlePermissions("往来单位").LuRu;
    },
    supplementPermissions() {
      return handleOtherPerms("补录单据");
    },
    printPermissions() {
      return handleOtherPerms("单据可多次打印");
    },
    /**销售价格低于成本价预警 */
    isBelowCost() {
      return sysConfig().sell_below_cost_alarm;
    },
    /**单据保存后立即开新单 */
    isSaveNewOrder() {
      return sysConfig().open_new_order_after_document_saved;
    },
    /**单据保存后立即审核 */
    isSaveExamine() {
      return sysConfig().verify_order_after_document_saved;
    },
    /**单据审核后立即开新单 */
    isExamineNewOrder() {
      return sysConfig().open_new_order_after_document_verify;
    },
    // 2、启用价格跟踪
    PriceTracking() {
      return sysConfig().enable_price_tracking;
    },
    // 3、启用折扣率跟踪
    discountTracking() {
      return sysConfig().enable_discount_tracking;
    },
    // 保存时单价为0不提示
    isInputSkip() {
      return sysConfig().unit_price_zero_no_prompt;
    },
  },
  created() {
    let accountBook = Vue.ls.get(ACCOUNT_BOOK);
    this.accountBookId = accountBook && accountBook.id;
    this.getData();

    if (!this.$route.params.billId) {
      //开新单
      this.onNewOrder()
    }
  },
  watch: {
    orderStatus() {
      this.handleOperationData();
    },
    $route: {
      immediate: true,
      handler() {
        if (this.$route.name == "other-otherDelivary") {
          let bId = this.$route.params.billId;
          if (bId && bId != this.billId) {
            this.billId = bId;
            this.getOrderDetailById();
          }
        }
      },
    },
    "queryData.xghCompanyId": {
      deep: true,
      handler() {
        this.totalCompanys.forEach((item) => {
          if (item.id == this.queryData.xghCompanyId) {
            this.companyName = item.companyName;
          }
        });
      },
    },
  },
  data() {
    return {
      billId: "",
      pageName: "其他出库单",
      accountBookId: "",
      // 传递给弹框的数据
      tipsData: {
        tipsWords: "",
        tipsMark: "",
        resultType: -1, //1、保存或编辑成功 2、审核成功
      },
      /**操作日志 */
      logTitle: "",
      paymentTitleName: "", //支付弹框名称
      paymentType: "", //支付弹窗类型 1：物流 2：收款
      showWlTips: false,
      operationValue: "操作",
      operationData: [],
      exchangeValue: "调单",
      exchangeOptions: ["调用采购入库单", "调其他入库单"],
      importValue: "导入",
      importOptions: [
        {
          value: "导入",
          label: "导入",
        },
        {
          value: "导出",
          label: "导出",
        },
      ],
      // 供应商
      gysOptions: [],
      // 出货仓库
      ckOptions: [],
      // 新增仓库数据
      newWhData: {},
      cklxOptions: [],
      // 经手人
      jsrOptions: [],
      // 税率
      taxRate: 0,
      // 单位
      dwOptions: [],
      deptOptions: [], //出入库部门
      companyName: "", //供应商id
      // 查询条件数据
      queryData: {
        id: "",
        orderState: "", //订单状态 0.待审核5.审核通过10.作废15.反审20.红冲25.终止30.完成
        orderNumber: "", // 单据编号
        xghCompanyId: "", //供应商id
        xghOutStorehouseId: "", //出货仓库id
        sysUserId: "", //经手人id
        invoiceType: "0", // 发票类型
        outTime: "", //订单日期
        orderStatus: "0", //订单状态 0.待审核5.审核通过10.作废15.反审20.红冲25.终止30.完成
        orderType: 26, ////采购订单1/采购入库单2/采购退货单3/采购换货单4/销售订单5/销售出库单6/销售退货单7/销售换货单8/盘点单9/报损单10
        isSupplement: false, //是否补单
        orderRebate: "100", //整单折扣率
        orderDiscountPrice: 0, //整单优惠金额
        bankName: "", // 收款账户
        bankId: "", // 账户id
        collectionPrice: 0, //预付定金
        remark: "", //备注
        postscript: "", //附记
        allPrice: formatMoney(0), // 整单优惠前总金额
        receivablePrice: formatMoney(0), //应收款
        orderAllPrice: 0, //订单总金额 订单总金额=整单折扣金额+优惠金额+预付定金+实付金额
        owePrice: formatMoney(0), //本次欠款金额
        createName: "", //制单人
        createOrderDate: "", //制单日期（当前日期）
        xghOutDeptId: "", //出货仓库
        xghOutType: "", //出货类型

        /**物流信息 */
        expressStatus: false,
        xghExpressId: "", //物流公司id
        expressNumber: "", //物流单号
        xghExpressDetailId: "", //物流代收信息id
        expressPayStatus: false, //物流状态 1.运费已付 0.未付
        expressPayPrice: "0", //物流代付金额
        expressPrice: 0.0, //运费
      },
      // 表格数据
      tableData: [],

      // 列配置数据
      defaultColumnData: [],
      TableConfig: {
        // 表头数据
        columnData: {
          idx: {
            isShow: true,
            cellWidth: "70px",
            morenName: "序号",
            zidingyiName: "",
            morenState: true,
            zidingyiState: true,
            noModify: true,
            props: "idx",
          },
          goodsNumber: {
            isShow: true, //是否显示当前列
            showLength: true,
            cellWidth: "150px",
            morenName: "商品编码",
            zidingyiName: "",
            morenState: true,
            zidingyiState: true,
            noModify: true,
            props: "goodsNumber",
          },
          goodsCode: {
            isShow: true,
            cellWidth: "150px",
            morenName: "条形码",
            zidingyiName: "",
            morenState: true,
            zidingyiState: true,
            noModify: false,
            props: "goodsCode",
          },
          goodsName: {
            isShow: true,
            isRequired: true,
            showType: "table",
            cellWidth: "150px",
            morenName: "商品名称",
            zidingyiName: "",
            morenState: true,
            zidingyiState: true,
            noModify: true,
            props: "goodsName",
          },
          norms: {
            isShow: true,
            cellWidth: "100px",
            morenName: "规格",
            zidingyiName: "",
            morenState: true,
            zidingyiState: true,
            props: "norms",
          },
          unit: {
            isShow: true,
            showType: "selectDw",
            cellWidth: "100px",
            morenName: "单位",
            zidingyiName: "",
            morenState: true,
            zidingyiState: true,
            props: "unit",
          },
          unitList: {
            isShow: false,
            morenName: "单位数据",
            zidingyiName: "",
            morenState: true,
            zidingyiState: true,
            props: "unitList",
          },
          xghStorehouseId: {
            isShow: true,
            isRequired: true,
            showType: "selectCk",
            cellWidth: "120px",
            morenName: "出货仓库",
            zidingyiName: "",
            morenState: true,
            zidingyiState: true,
            props: "xghStorehouseId",
          },
          numberShow: {
            isShow: true,
            isRequired: true,
            showType: "input",
            isSum: true,
            sumValue: 0,
            cellWidth: "100px",
            morenName: "数量",
            zidingyiName: "",
            morenState: true,
            zidingyiState: true,
            props: "numberShow",
          },
          salePriceShow: {
            isShow: true,
            showType: "input",
            cellWidth: "100px",
            morenName: "单价",
            zidingyiName: "",
            morenState: true,
            zidingyiState: true,
            props: "salePriceShow",
          },
          allPriceShow: {
            isShow: true,
            showType: "input",
            isSum: true,
            sumValue: 0,
            cellWidth: "100px",
            morenName: "金额",
            zidingyiName: "",
            morenState: true,
            zidingyiState: true,
            props: "allPriceShow",
          },
          // salePrice: {
          //   isShow: true,
          //   showType: 'input',
          //   cellWidth: '100px',
          //   morenName: '零售价',
          //   zidingyiName: '',
          //   morenState: true,
          //   zidingyiState: true,
          //   props: 'salePrice',
          // },
          // salePrice: {
          //   isShow: true,
          //   showType: 'input',
          //   cellWidth: '100px',
          //   morenName: '零售价小计',
          //   zidingyiName: '',
          //   morenState: true,
          //   zidingyiState: true,
          //   props: 'salePrice',
          // },
          isGive: {
            isShow: true,
            showType: "check",
            cellWidth: "60px",
            morenName: "赠品",
            zidingyiName: "",
            morenState: true,
            zidingyiState: true,
            props: "isGive",
          },
          remark: {
            isShow: true,
            showType: "input",
            cellWidth: "100px",
            morenName: "备注",
            zidingyiName: "",
            morenState: true,
            zidingyiState: true,
            props: "remark",
          },
        },
        // 表格数据
        tableData: [],
      },
      orderId: "", // 单据id
      orderFlag: 0, //先点上一单传1，先点下一单传2，点新单重置
      orderStatus: 0, // 当前单据的状态 66表示新单
      updateId: "", // 修改列配置时返回的id
      showLiepeizhi: false, //是否显示列配置
      scanCode: "",
      /**定义单据信息对象 */
      // 传递给操作日志的值
      logData: {
        orderId: -1,
        orderType: "其他出库单",
      },
      /**信用额度预警 */
      isCreditLimit: false,
      showPriceZeroDialog: false,
      priceZeroGoodsData: {}, //价格为零的商品
      showPriceBelowDialog: false,
      priceBelowGoodsData: {}, //销售价低于成本价的商品
      negativeInventory: false,
      showNegativeInventoryDialog: false,
      negativeInventoryData: {}, //负库存的商品
      pageNo: 0, //
      pageTotal: 1,
      lowerLoading: false,
      upperLoading: false,
      url: {
        api: "其他出库单",
        exportXlsUrl:
          "/xghSaleStorehouseOrder/xghSaleStorehouseOrder/exportOtherSalesXls",
      },
      dialogVisible: false,
      dialogTitle: "",
      inOrOut: 2,
      printData: {},
      saveData: "", // 预存保存后的数据
    };
  },
  mounted() {
    //
  },
  methods: {
    supplementChange(val) {
      if (!val) {
        this.queryData.outTime = this.$formatDateTime();
      }
    },
    // 新增
    handleShortcutKeyAdd() {
      this.onNewOrder();
    },
    // 保存
    handleShortcutKeySave() {
      if (!this.buttonsPermissions.LuRu) {
        this.$elMessage.warning("未拥有保存权限！");
      } else if (this.saveBtnStatus) {
        this.$elMessage.warning("当前状态不支持保存操作！");
      } else {
        this.onSubmit();
      }
    },
    // 审核
    handleShortcutKeyExamine() {
      if (!this.buttonsPermissions.ShenHe) {
        this.$elMessage.warning("未拥有审核权限！");
      } else if (this.auditBtnStatus) {
        this.$elMessage.warning("当前状态不支持审核操作！");
      } else {
        this.onToExamine();
      }
    },
    // 打印
    handleShortcutKeyPrint() {
      if (!this.buttonsPermissions.DaYin) {
        this.$elMessage.warning("未拥有打印权限！");
      } else if (this.orderStatus == 66) {
        this.$elMessage.warning("当前状态不支持打印操作！");
      } else {
        // 可以多次打印设置
        if (this.printPermissions) {
          this.$refs.print.show(this.printData, this.columnData, this.url.api);
        } else {
          if (this.$lcStorage.get("printLimitValue")) {
            // 获取打印次数
            this.getPrintNum(this.billId, () => {
              this.$refs.print.show(this.printData, this.columnData, this.url.api);
            });
          } else {
            this.$refs.print.show(this.printData, this.columnData, this.url.api);
          }
        }
      }
    },

    // 获取数据 从销售订单复制过来
    getData() {
      this.getGysStorage(); //供应商数据
      this.getWarehouseData(); // 获取所有仓库数据
      this.getStaffData(); // 获取所有员工数据
      this.selectTitle();
      this.getDeptList();
      this.getTypeList();
    },
    //查看单据详情
    getOrderDetailById() {
      getAction("/xghSaleStorehouseOrder/xghSaleStorehouseOrder/getBuyOrderById", {
        id: this.billId,
      }).then((res) => {
        if (res.success) {
          this.handleData(res.result);
        } else {
          this.$elMessage.error(res.message);
        }
      });
    },
    //出库类型
    getTypeList() {
      getAction("/xghotherordertype/xghOtherOrderType/list", { type: 2 }).then((res) => {
        console.log(res);
        if (res.success) {
          let list = res.result || [];
          this.cklxOptions = list;
          // 修改数据之后查询选择的项是否被删除
          if (
            this.queryData.xghOutType &&
            !list.some((item) => item.id === this.queryData.xghOutType)
          ) {
            this.queryData.xghOutType = "";
          }
        } else {
          this.$elMessage.error(res.message);
        }
      });
    },
    // 刷新出库类型数据
    onUpdataType() {
      this.getTypeList();
    },
    onSelectData(val) {
      this.queryData.xghOutType = val.id;
      this.dialogVisible = false;
    },
    // 出入库部门
    getDeptList() {
      // 所属部门
      getAction("/dept/xghAccountBookDept/getDeptByAbId", {}).then((res) => {
        if (res.code === 200) {
          this.deptOptions = res.result || [];
        }
      });
    },
    /**
     * 初始化默认获取缓存中存储的曾经点击过的供应商数据
     */
    getGysStorage() {
      getAction("/xghCompany/xghCompany/listNoPage", {}).then((res) => {
        if (res.code === 200) {
          this.gysOptions = res.result;
          this.totalCompanys = res.result;
        } else {
          this.$elMessage.error(res.message);
        }
      });
    },
    /**
     * 获取所有仓库数据
     */
    getWarehouseData() {
      getAction("/xghStorehouse/xghStorehouse/queryListByPole", {}).then((res) => {
        if (res.code === 200) {
          this.ckOptions = res.result;
          this.ckOptions.forEach(item =>{
            if (item.isDefault == 1) {
              this.queryData.xghOutStorehouseId = item.id
            }
          })
          this.getXghStorehouseIdById(false)
          this.totalStores = res.result;
        } else {
          this.$elMessage.error(res.message);
        }
      });
    },
    /**
     * 获取所有员工数据
     */
    async getStaffData() {
      getAction("/dept/xghAccountBookDept/getAllDeptUsers", {}).then((res) => {
        if (res.code === 200) {
          this.jsrOptions = res.result;
          this.totalPersons = res.result;
          // 默认经手人设置
          this.queryData.sysUserId = this.$lcStorage.get('xghUser').id
        }
      });
    },
    invoiceTypeChange() {
      this.taxRate = this.getTaxRate();
      this.TableConfig.tableData.forEach((item) => {
        item.taxRate = this.taxRate;
      });
    },
    getTaxRate() {
      let config = sysConfig();
      if (this.queryData.invoiceType == "0") {
        return 0;
      } else if (this.queryData.invoiceType == "1") {
        return 0;
      } else if (this.queryData.invoiceType == "2") {
        return parseInt(config.tax_rate);
      } else if (this.queryData.invoiceType == "3") {
        return parseInt(config.vat_rate);
      }
    },
    // 处理操作下拉列表的启用禁用项
    handleOperationData() {
      if (this.orderStatus == 66 || this.orderStatus == 0) {
        this.importValue = "导入";
      } else {
        this.importValue = "导出";
      }
      //orderStatus 订单状态：0待审核、5审核通过、10作废、15反审、20红冲、25终止、30完成
      let allList = ["作废", "反审", "红冲", "复制单据", "办理过程"];
      let result = [];
      if (this.orderStatus == 0 || this.orderStatus == 15) {
        // 保存/之后状态，可作废，不可反审、红冲，可保存
        if (this.buttonsPermissions.ZuoFei) {
          result = ["作废"];
        }
      } else if (this.orderStatus == 5) {
        // 审核状态，不可作废，可反审、红冲，不可保存
        // 审核后
        if (this.buttonsPermissions.FanShen) {
          result.push("反审");
        }
        if (this.buttonsPermissions.HongChong) {
          result.push("红冲");
        }
      } else if (this.orderStatus == 10 || this.orderStatus == 20) {
        // 作废/红冲后状态，不可作废、反审、红冲，不可保存
      }
      if (this.orderStatus !== 66) {
        result = result.concat(["复制单据", "办理过程"]);
      }

      let resultList = [];
      allList.forEach((item) => {
        let newItem = {
          value: item,
          disabled: result.indexOf(item) == -1,
        };
        resultList.push(newItem);
      });
      this.operationData = resultList;
    },
    // 提醒弹框取消后操作
    onCancel(mark) {
      if (mark == "onChangeCk") {
        // 改变仓库
        this.getXghStorehouseIdById(true);
      }
    },
    // 提醒弹框确认后操作
    onYes(mark) {
      if (mark == "onNewOrder") {
        this.orderStatus = 0;
        this.onNewOrder();
      } else if (mark == "onUpper") {
        // 上一单
        this.switchoverBill(1);
      } else if (mark == "onLower") {
        // 下一单
        this.switchoverBill(2);
      } else if (mark == "onChangeCk") {
        // 改变仓库
        // 根据出货仓库选择商品里的仓库
        this.getXghStorehouseIdById(false);
      } else if (mark == "onToExamine") {
        // 审核
        this.updateOrder(5, "audit");
      } else if (mark == "onUnCheck") {
        // 反审
        this.checkReVerifyPermission()
      } else if (mark == "onToVoid") {
        // 作废
        this.updateOrder(10, "aborted");
      } else if (mark == "onToHongC") {
        // 红冲
        this.$refs.simplePrompt.show({
          index: 1,
          text: "确定要红冲当前的业务单据吗？</br>注：对应的应付款记录将会被自动红冲",
        });
      } else if (mark == "onToStop") {
        // 终止
        this.updateOrder(25);
      } else if (mark == "onToFinish") {
        // 完成
        this.updateOrder(30);
      } else if (mark == "onCopy") {
        // 复制单据
        if (this.orderStatus != 66) {
          this.orderStatus = 66;
          this.queryData.id = "";
          this.TableConfig.tableData.forEach((item) => {
            item.id = "";
            item.ignore = false;
            item.compulsory = "0";
            item.callDocumentId = undefined;
            item.callDocumentType = undefined;
          });
        }
        this.billId = ""; //单据ID置空
        this.queryData.orderNumber = ""; //单据编号置空
        this.queryData.orderIndex = ""; //`
        this.queryData.orderStatus_dictText = ""; //单据状态置空
        this.queryData.xghExpressDetailId = "";

        this.queryData.outTime = this.$formatDateTime();
        this.queryData.createOrderDate = this.$formatDateTime();
        this.queryData.createName = this.$lcStorage.get("xghUser").realname;

        this.$refs.simplePrompt.show({
          index: 0,
          text: "单据复制成功",
        });
      }
    },
    getHaveChange() {
      // //获取源数据，将订单状态置成新单状态
      let source = JSON.parse(JSON.stringify(this.$options.data().queryData));
      source.sysUserId = this.$lcStorage.get('xghUser').id
      this.ckOptions.forEach(item =>{
        if (item.isDefault == 1) {
          source.xghOutStorehouseId = item.id
        }
      })
      // // 获取现有数据，移除自动添加的值
      let current = JSON.parse(JSON.stringify(this.queryData));
      current.outTime = "";
      current.createOrderDate = "";
      current.createName = "";
      // // 判断当前数据是否和源数据相同，相同表示未做修改
      let sourceStr = JSON.stringify(source);
      let currentStr = JSON.stringify(current);
      // console.log(sourceStr);
      // console.log(currentStr);
      return sourceStr != currentStr;
    },
    // 点击开新单
    onNewOrder() {
      if (this.orderStatus === 66 && this.getHaveChange()) {
        this.tipsData.tipsWords = "当前单据还未保存，</br>是否继续？";
        this.tipsData.tipsMark = "onNewOrder";
        this.$refs.reminderRef.dialogVisible = true;
      } else {
        this.orderFlag = 0;
        this.pageNo = 0;
        this.pageTotal = 1;
        this.orderStatus = 66;
        this.billId = "";
        this.logData.orderId = -1;
        this.queryData = JSON.parse(JSON.stringify(this.$options.data().queryData));
        this.ckOptions.forEach(item =>{
          if (item.isDefault == 1) {
            this.queryData.xghOutStorehouseId = item.id
          }
        })
        this.queryData.outTime = this.$formatDateTime();
        this.queryData.createOrderDate = this.$formatDateTime();
        this.queryData.createName = this.$lcStorage.get("xghUser").realname;
        // 默认经手人设置
        this.queryData.sysUserId = this.$lcStorage.get('xghUser').id
        this.isCreditLimit = false;
        this.negativeInventory = false;
        this.$nextTick(() => {
          this.$refs.newTableRef.getSubData();
          this.$refs.newTableRef.onResetCommodity()
        });
      }
    },
    showTips(msg) {
      this.$elMessage({
        showClose: true,
        message: msg || "",
        type: "error",
        iconClass: "el-icon-warning-outline",
        duration: 3000,
      });
    },
    priceZeroCallback(data) {
      if (data.type == "once") {
        this.TableConfig.tableData[data.index].ignore = true;
        this.showPriceZeroDialog = false;
        this.onSubmit();
      } else if (data.type == "cancel") {
        this.showPriceZeroDialog = false;
      } else if (data.type == "all") {
        for (let index = 0; index < this.TableConfig.tableData.length; index++) {
          let element = this.TableConfig.tableData[index];
          element.ignore = true;
        }
        this.showPriceZeroDialog = false;
        this.onSubmit();
      }
    },
    getZeroByGoods() {
      let list = this.TableConfig.tableData;
      for (let index = 0; index < list.length; index++) {
        const element = list[index];
        if (element.salePrice == formatMoney(0) && !element.ignore && !element.isGive) {
          this.showPriceZeroDialog = true;
          let item = {
            id: element.id,
            name: `商品[${element.goodsName}]销售单价`,
            index,
          };
          this.priceZeroGoodsData = item;
          return true;
        }
      }
      return false;
    },
    priceBelowCallback(data) {
      console.log(data);
      if (data.type == "cancel") {
        this.showPriceBelowDialog = false;
      } else {
        if (data.index == 1) {
          this.showPriceBelowDialog = false;
          this.isCreditLimit = true;
          this.onSubmit();
        } else {
          this.showPriceBelowDialog = false;
          for (let index = 0; index < this.TableConfig.tableData.length; index++) {
            let element = this.TableConfig.tableData[index];
            element.compulsory = "1";
          }
          this.onSubmit();
        }
      }
    },
    getBelowByGoods() {
      let list = this.TableConfig.tableData;
      let goodsName = "";
      for (let index = 0; index < list.length; index++) {
        const element = list[index];
        if (
          delcommafy(element.salePrice) < parseFloat(element.costPrice) &&
          element.compulsory == 0
        ) {
          if (goodsName.length == 0) {
            goodsName = element.goodsName;
          } else {
            goodsName = goodsName + "，" + element.goodsName;
          }
        }
      }
      if (goodsName.length > 0) {
        this.showPriceBelowDialog = true;
        let item = {
          id: "",
          name: `商品[${goodsName}]销售单价低于成本价`,
          index: 0,
        };
        this.priceBelowGoodsData = item;
        return true;
      }
      return false;
    },
    negativeInventoryCallBack(data) {
      if (data.type == "cancel") {
        this.showNegativeInventoryDialog = false;
      } else {
        this.showNegativeInventoryDialog = false;
        this.negativeInventory = true;
        if (data.index == 1) {
          this.onSubmit();
        } else if (data.index == 2) {
          // 继续审核
          this.updateOrder(5, "audit");
        } else if (data.index == 3) {
          // 继续红冲
          this.updateOrder(20)
        }
      }
    },
    // 保存
    async onSubmit() {
      // 先判断是否有修改或录入权限
      if (this.billId) {
        if (!this.buttonsPermissions.XiuGai) {
          this.showTips("没有修改权限！");
          return;
        }
      }
      if (!this.queryData.xghCompanyId) {
        this.$elMessage.warning("客户不能为空，请选择！");
        return;
      }
      if (!this.queryData.xghOutStorehouseId) {
        this.$elMessage.warning("出货仓库不能为空，请选择！");
        return;
      }
      if (!this.queryData.xghOutType) {
        this.$elMessage.warning("出货类型不能为空，请选择！");
        return;
      }

      if (this.isInputSkip) {
        if (this.getZeroByGoods()) {
          return;
        }
      }
      if (this.isBelowCost) {
        if (this.getBelowByGoods()) {
          return;
        }
      }

      let queryObj = JSON.parse(JSON.stringify(this.queryData));
      // 给补单 赠品的数据转换为后端需要的类型
      queryObj.isReplacementOrder = queryObj.isSupplement ? "0" : "1"; //是否补单-0：是 1:不是
      queryObj.expressStatus = queryObj.expressStatus ? "0" : "1"; //物流状态-0：开启 1:关闭
      queryObj.expressPayStatus = queryObj.expressPayStatus ? "1" : "2"; //物流费付款状态1：已付款，2：未付

      let count = 0;
      let digest = [];
      let list = this.TableConfig.tableData
        .map((item) => {
          if (item.goodsId) {
            item.isGift = item.isGive ? "0" : "1"; //赠品0:是赠品1：不是赠品
            item.salePrice = delcommafy(item.salePrice);
            item.allPrice = delcommafy(item.allPrice);
            item.discountUnitPrice = delcommafy(item.discountUnitPrice);
            item.taxUnitPrice = delcommafy(item.taxUnitPrice);
            item.taxPrice = delcommafy(item.taxPrice);
            item.xghAccountBookId = this.accountBookId;
            item.saleOrderType = "2"; //单据类型1：入库2;出库
            if (Number(item.number) == 0) {
              count++;
            }
            digest.push(`[${item.goodsName},${item.numberShow}${item.unit}]`);
            // 特殊功能
            if (item.attributeOrderInfoRequest) {
              item.attributeOrderInfoRequest.forEach((item1) => {
                item1.orderType = '26'
                item1.mainId = this.billId
                item1.price = item.taxUnitPrice
                item1.accountBookId = this.accountBookId
                item1.outStoreId = item.xghStorehouseId
                item1.outNumber = item1.number
              })
            }

            return item;
          }
        })
        .filter((item) => {
          return item != undefined;
        });
      if (list.length == 0) {
        this.$elMessage.warning("商品不能为空，请选择商品！");
        return;
      } else if (count > 0) {
        this.$elMessage.warning("商品数量不能为0");
        return;
      }

      let orderObj = {
        ...queryObj,
        orderDiscountPrice: delcommafy(queryObj.orderDiscountPrice), //移除需要参与计算的数值千分位分隔符
        owePrice: delcommafy(queryObj.owePrice),
        collectionPrice: delcommafy(queryObj.collectionPrice),
        allPrice: delcommafy(queryObj.allPrice),
        receivablePrice: delcommafy(queryObj.receivablePrice),
        expressPayPrice: delcommafy(queryObj.expressPayPrice),
        status: 0, //完成状态0.待审核5.审核通过10.作废15.反审20.红冲25.终止30.完成
        xghAccountBookId: this.accountBookId,
        xghSaleStorehouseOrderInfoList: list,
        compulsoryCredit: this.isCreditLimit ? "1" : "0",
        negativeInventory: this.negativeInventory ? "1" : "0",
        createOrderDate: this.billId ? queryObj.createOrderDate : "",
        summary: digest.join(";"), //摘要
      };

      // 总信息
      let obj = {
        saleStorehouseOrderPage: orderObj,
      };
      console.log("保存：", obj);

      var res = {};
      // 修改
      if (this.billId) {
        // 先判断用户是否拥有修改权限
        if (this.buttonsPermissions.XiuGai) {
          res = await putAction(
            "/xghSaleStorehouseOrder/xghSaleStorehouseOrder/edit",
            obj
          );
        } else {
          this.showTips("没有修改权限！");
          return;
        }
      } else {
        // 新增
        res = await postAction("/xghSaleStorehouseOrder/xghSaleStorehouseOrder/add", obj);
      }
      if (res.code === 200) {
        if (this.billId) {
          this.$elMessage.success("修改成功！");
        } else {
          this.$elMessage.success("新增成功！");
        }
        // this.tipsData.resultType = 1
        // this.$refs.successRef.dialogVisible = true
        this.handleData(res.result);
        this.isCreditLimit = false;
        this.negativeInventory = false;
        this.toSaveOrExamine();
      } else if (res.code == 303) {
        this.showPriceBelowDialog = true;
        let item = {
          id: "",
          name: `商品${res.message}销售单价低于成本价`,
          index: 0,
        };
        this.priceBelowGoodsData = item;
      } else if (res.code == 101) {
        this.showPriceBelowDialog = true;
        let item = {
          id: "",
          name: `${res.message}`,
          index: 1,
        };
        this.priceBelowGoodsData = item;
      } else if (res.code == 48) {
        let config = sysConfig();
        let show = false;
        let name = "";
        if (config.allow_negative_inventory) {
          // 允许负库存
          show = true;
          name = `商品${res.message}库存不足, 是否继续保存?`;
        } else {
          show = false;
          name = `商品${res.message}库存不足, 并且不允许负库存, 无法进行保存!`;
        }
        this.showNegativeInventoryDialog = true;
        let item = {
          id: "",
          name: name,
          index: 1,
          show: show,
        };
        this.negativeInventoryData = item;
      } else {
        this.showTips(res.message);
      }
    },

    // 当操作成功后点击了确定按钮之后进行的下一步操作：
    onOptionSuccess() {
      // if (this.tipsData.resultType == 1) {
      //   this.tipsData.resultType == -1
      //   // 保存成功了
      //   console.log('操作成功后点击确定按钮了')
      //   this.toSaveOrExamine()
      // } else if (this.tipsData.resultType == 2) {
      //   this.tipsData.resultType == -1
      //   // 审核成功了
      //   console.log('审核成功后点击确定按钮了')
      //   this.afterExamine()
      // }
    },
    // 单据保存后的走向
    toSaveOrExamine() {
      if (this.isSaveExamine && this.buttonsPermissions.ShenHe) {
        // 保存后立即审核,且有审核权限
        setTimeout(() => {
          this.onToExamine();
        }, 1000);
      } else if (this.isSaveNewOrder && this.buttonsPermissions.LuRu) {
        // 如果保存后立即开新单,并且有新增权限
        this.onYes("onNewOrder");
      }
    },
    afterExamine() {
      // 如果审核后立即开新单
      if (this.isExamineNewOrder && this.buttonsPermissions.LuRu) {
        this.onYes("onNewOrder");
      }
    },
    // 审核单据
    onToExamine() {
      let queryData = JSON.parse(JSON.stringify(this.queryData));
      let tableData = JSON.parse(JSON.stringify(this.TableConfig.tableData));
      queryData.xghSaleStorehouseOrderInfoList.forEach((item) => {
        // delete item["unitList"];
        delete item["visible"];
      });
      tableData.forEach((item) => {
        // delete item["unitList"];
        delete item["visible"];
      });
      var data = JSON.parse(
        JSON.stringify({
          ...queryData,
          ...tableData,
        })
      );
      if (JSON.stringify(data) === JSON.stringify(this.saveData)) {
        this.tipsData.tipsWords = "确定要审核当前的单据吗？";
        this.tipsData.tipsMark = "onToExamine";
        this.$refs.reminderRef.dialogVisible = true;
      } else {
        this.$elMessage.warning("请先保存！");
      }
    },
    // 操作选择
    operationSelect(value) {
      switch (value) {
        case "作废":
          this.tipsData.tipsWords = "确定要作废当前的单据吗？";
          this.tipsData.tipsMark = "onToVoid";
          this.$refs.reminderRef.dialogVisible = true;
          break;
        case "反审":
          this.tipsData.tipsWords = '确定要反审当前的单据吗？'
          this.tipsData.tipsMark = 'onUnCheck'
          this.$refs.reminderRef.dialogVisible = true
          // this.checkReVerifyPermission();
          break;
        case "红冲":
          // this.tipsData.tipsWords = '确定要红冲当前的单据吗？'
          // this.tipsData.tipsMark = 'onToHongC'
          // this.$refs.reminderRef.dialogVisible = true
          // 红冲
          this.$refs.simplePrompt.show({
            index: 1,
            text: "确定要红冲当前的业务单据吗？</br>注：对应的应付款记录将会被自动红冲",
          });
          break;
        case "终止":
          this.tipsData.tipsWords = "确定要终止当前的单据吗？";
          this.tipsData.tipsMark = "onToStop";
          this.$refs.reminderRef.dialogVisible = true;
          break;
        case "完成":
          this.tipsData.tipsWords = "确定要完成当前的单据吗？";
          this.tipsData.tipsMark = "onToFinish";
          this.$refs.reminderRef.dialogVisible = true;
          break;
        case "复制单据":
          this.tipsData.tipsWords = "确定要复制当前的单据吗？";
          this.tipsData.tipsMark = "onCopy";
          this.$refs.reminderRef.dialogVisible = true;
          break;
        case "办理过程":
          this.$refs.operationLogRef.getData(this.logData);
          this.logTitle = "办理过程";
          this.$refs.operationLogRef.dialogVisible = true;
          break;
        default:
          break;
      }
      this.operationValue = "操作";
    },
    // 调单选择
    exchangeSelect(item) {
      //['调用采购入库单', '调其他入库单'],
      console.log(item);
      switch (item) {
        case "调用采购入库单":
          this.$refs.transferBill.show({
            title: "采购入库单",
            api: "调单-采购入库单",
            detailApi: "调单-采购入库单明细",
            listUrl: "/xghBuyOrder/xghBuyOrder/list", //采购入库列表
            detailUrl: "/xghBuyOrder/xghBuyOrder/getBuyOrderById", //采购订单明细
            orderKey: "buyOrderPage",
            goodsListKey: "xghBuyOrderInfoList",
            xghCompanyId: this.queryData.xghCompanyId,
            orderStatusKey: "buyOrderStatus",
          });
          break;
        case "调其他入库单":
          this.$refs.transferBill.show({
            title: "其他入库单",
            api: "调单-其他入库单",
            detailApi: "调单-其他入库单明细",
            listUrl: "/xghBuyOrder/xghBuyOrder/list", //采购入库列表
            detailUrl: "/xghBuyOrder/xghBuyOrder/getBuyOrderById", //采购订单明细
            orderKey: "buyOrderPage",
            goodsListKey: "xghBuyOrderInfoList",
            xghCompanyId: this.queryData.xghCompanyId,
            orderStatusKey: "buyOrderStatus",
          });
          break;
        default:
          break;
      }
      this.exchangeValue = "调单";
    },
    // 调单回调
    transferBillCallback(data) {
      console.log(data);
      let billObj = data.billObj;
      this.queryData = {
        ...this.queryData,
        xghCompanyId: billObj.xghCompanyId,
        xghOutStorehouseId: billObj.xghStorehouseId,
        sysUserId: billObj.sysUserId,
        remark: `${billObj.remark || ""}${this.queryData.remark}`,
      };
      if (billObj.xghCompanyId) {
        let h = this.gysOptions.some(item => item.id == billObj.xghCompanyId)
        if (!h) {
          this.getGysStorage()
        }
      }

      let goodsList = data.goodsList;
      let index = this.TableConfig.tableData.length
      goodsList.forEach((val) => {
        let item = {
          ...val,
          isGive: val.isGive == "1" ? false : true, //赠品0:是赠品1：不是赠品
          number: formatFour(val.number),
          numberShow: formatNumber(val.number),
          taxRate: 0,
          salePrice: formatFour(val.salePrice),
          allPrice: formatFour(val.allPrice),
          discountUnitPrice: formatFour(val.discountUnitPrice),
          taxUnitPrice: formatFour(val.taxUnitPrice),

          salePriceShow: formatPrice(val.salePrice),
          allPriceShow: formatMoney(val.allPrice),
          discountUnitPriceShow: formatPrice(val.discountUnitPrice),
          taxUnitPriceShow: formatPrice(val.taxUnitPrice),
          unitList: val.goodsManyNorms,
          callDocumentId: val.callDocumentId,
          callDocumentType: val.callDocumentType,
           // 特殊功能
           attributeOrderInfoRequest: getAttributeOrderInfoRequest(val.attributeGoodsResponse, true),
          specialColorSize: (val.specialFunctionType || '').includes('1'),
          showSpeial: true
        };
        if (
          this.TableConfig.tableData.length == 1 &&
          !this.TableConfig.tableData[0].goodsId
        ) {
          index = 0
          this.TableConfig.tableData.splice(0, 1, item);
        } else {
          this.TableConfig.tableData.push(item);
        }
        this.$refs.newTableRef.handlePrice(index)
        index++
      });
    },
    // 导入
    importExcel() {
      this.$refs.daoru.dialogVisible = true;
    },
    importData(val) {
      if (val.success) {
        this.$elMessage.success(val.message);
        let result = val.result && val.result.records || []
        result.map((item) => {
          item.goodsName = item.goodsId_dictText;
          item.salePrice = formatPrice(item.salePrice);
          item.isGive = item.isGift == "0" ? true : false; //赠品0:是赠品1：不是赠品
          item.unitList = item.goodsManyNorms;
          item.unitScale = this.getUnitScale(item.goodsManyNorms, item.unit, 'scale');
          item.baseUnit = this.getUnitScale(item.goodsManyNorms, item.unit, 'id')
          item.taxRate = 0
          item.orderRebate = 100
          item.numberShow = formatNumber(item.number)
          item.salePriceShow = formatPrice(item.salePrice)
          item.allPriceShow = formatMoney(item.allPrice)
          return item;
        });

        if (
          this.TableConfig.tableData.length == 1 &&
          !this.TableConfig.tableData[0].goodsId
        ) {
          this.TableConfig.tableData = result;
        } else {
          this.TableConfig.tableData = this.TableConfig.tableData.concat(result);
        }
      } else {
        this.$elMessage.error(val.message);
      }
    },
    getUnitScale(unitList, defaultUnit, key) {
      if (!unitList || !defaultUnit) {
        return "1";
      }
      for (let index = 0; index < unitList.length; index++) {
        const element = unitList[index];
        if (element.unit == defaultUnit) {
          return element[key];
        }
      }
    },
    // 导出
    exportExcel() {
      let queryParam = {
        fileName: this.pageName,
        orderId: this.billId,
      };
      this.handleExportXlsByStaff(this.pageName, queryParam);
    },
    // 分享
    onShare() {
      if (!this.billId) {
        this.$elMessage.warning('未保存单据无法分享！')
      } else if (this.buttonsPermissions.FenXiang) {
        let base = window._CONFIG['domianURL'].replace('api', '').replace('10030', '9047')        
        let bookId = Vue.ls.get(ACCOUNT_BOOK).id
        let url = `${base}share?from=qtckd&aid=${bookId}&bid=${this.billId}`
        window.open(url)
      } else {
        this.$elMessage.warning('没有分享权限！')
      }
    },
    // 单据核对
    onCheckBill() {
      let list = [];
      let ids = [];
      for (let index = 0; index < this.TableConfig.tableData.length; index++) {
        const item = this.TableConfig.tableData[index];
        let goodsId = item.goodsId;
        if (ids.indexOf(goodsId) == -1) {
          ids.push(item.goodsId);
          list.push({
            goodsCode: item.goodsCode,
            goodsName: item.goodsName,
            number: item.number,
          });
        } else {
          let index = ids.indexOf(goodsId);
          list[index].number += item.number;
        }
      }
      this.$refs.billContrast.show(list);
    },
    // 点击修改表样式
    onClickTable(row) {
      this.tableData.forEach((item) => {
        if (item.id == row.id) {
          item.xhState = false;
        } else {
          item.xhState = true;
        }
      });
    },
    // 当前选择商品数据
    onSelectCommodity(val) {
      if (this.$lcStorage.get("spHistoricalRecords")) {
        let arr = this.$lcStorage.get("spHistoricalRecords");
        arr.unshift(val);
        this.$lcStorage.set("spHistoricalRecords", arr);
      } else {
        let arr = [val];
        this.$lcStorage.set("spHistoricalRecords", arr);
      }
      let threeArr = this.selectDataHas(this.$lcStorage.get("spHistoricalRecords"));
      this.$lcStorage.set("spHistoricalRecords", threeArr);
      this.tableData.forEach((item) => {
        if (!item.xhState) {
          for (const key in item) {
            item[key] = val[key];
          }
        }
      });
    },
    // 查询
    async selectTitle() {
      let obj = await this.$setColumn.selectColumn(this.url.api);
      if (obj.code === 200) {
        this.updateId = obj.updateId;
        this.TableConfig.columnData = obj.columnData;
      } else if (obj.code === 500) {
        let id = await this.$setColumn.addColumn(
          this.url.api,
          this.TableConfig.columnData,
          0,
          this.updateId
        );
        this.updateId = id;
      }
    },
    // 列配置修改后数据获取
    async onSaveColumn(value) {
      this.TableConfig.columnData = handleArrayToObject(value, "props");
      let res = await this.$setColumn.editColumn(
        this.url.api,
        this.TableConfig.columnData,
        this.updateId
      );
      if (res.code == 200) {
        this.$elMessage.success(res.message);
      } else {
        this.$elMessage.error(res.message);
      }
    },
    // 单位改变触发
    onHandleUnit(val, i, transmit) {
      let sc = this.TableConfig.tableData[i].unitScale
      let sc1 = this.getUnitScale(val.unitList, val.unit, 'scale')
      this.TableConfig.tableData[i].unitScale = sc1
      this.TableConfig.tableData[i].baseUnit = this.getUnitScale(val.unitList, val.unit, 'id')
      if (sc && sc > sc1) {
        this.TableConfig.tableData[i].costPrice = this.TableConfig.tableData[i].costPrice / sc
      }else {
        this.TableConfig.tableData[i].costPrice = accMul(this.TableConfig.tableData[i].costPrice, sc1)
      }
      
      // 设置价格的默认值
      this.$refs.newTableRef.focusPrice('', i, this.TableConfig.tableData[i], transmit)
    },
    // 修改附记
    async updatePostScript() {
      let orderStateNum = Number(this.orderStatus);
      if (orderStateNum >= 5 && orderStateNum < 66) {
        const res = await getAction(
          "/xghSaleStorehouseOrder/xghSaleStorehouseOrder/addPostScript",
          {
            orderId: this.billId,
            postscript: this.queryData.postscript,
          }
        );
        if (res.code == 200) {
          this.$elMessage.success("附记修改成功！");
        } else if (res.code === 500) {
          this.$elMessage.error(res.message);
        }
      }
    },
    /**
     * 父组件处理子组件获取到的商品信息数据字段名不统一问题
     * @param tableData 子组件中表格的数据
     * @param index 当前选中this.TableConfig.tableData的索引
     * @param val 从商品表中选中的商品数据
     */
    onHandleSpData(tableData, index, val) {
      // 根据出货仓库选择商品里的仓库
      for (const key in tableData[index]) {
        // this.TableConfig.tableData[index][key] = val[key]
        this.TableConfig.tableData[index].goodsNumber = val.goodsNumber;
        this.TableConfig.tableData[index].goodsCode = val.barCode;
        this.TableConfig.tableData[index].goodsId = val.id;
        this.TableConfig.tableData[index].goodsName = val.goodsName;
        this.TableConfig.tableData[index].norms = val.specs;
        this.TableConfig.tableData[index].unit = val.defaultUnit;
        this.TableConfig.tableData[index].unitList = val.goodsManyNorms;
        this.TableConfig.tableData[
          index
        ].xghStorehouseId = this.queryData.xghOutStorehouseId;
        this.TableConfig.tableData[index].number = formatFour(val.number);
        this.TableConfig.tableData[index].numberShow = formatNumber(val.number);
        this.TableConfig.tableData[index].isGive = false;
        this.TableConfig.tableData[index].remark = val.goodsRemark;
        this.TableConfig.tableData[index].salePrice = formatFour(val.salePrice);
        this.TableConfig.tableData[index].allPrice = formatFour(val.salePrice);
        this.TableConfig.tableData[index].discountUnitPrice = formatFour(val.salePrice);
        this.TableConfig.tableData[index].taxUnitPrice = formatFour(val.salePrice);

        this.TableConfig.tableData[index].salePriceShow = formatPrice(val.salePrice);
        this.TableConfig.tableData[index].allPriceShow = formatMoney(val.salePrice);
        this.TableConfig.tableData[index].discountUnitPriceShow = formatPrice(
          val.salePrice
        );
        this.TableConfig.tableData[index].taxUnitPriceShow = formatPrice(val.salePrice);
        this.TableConfig.tableData[index].ignore = false;
        this.TableConfig.tableData[index].useNumber = val.useNumber;
        this.TableConfig.tableData[index].compulsory = "0";
        this.TableConfig.tableData[index].costPrice = val.costPrice;
        this.TableConfig.tableData[index].taxRate = this.taxRate;
        this.TableConfig.tableData[index].discountRate = this.queryData.orderRebate;

        this.TableConfig.tableData[index].specialFunctionType = val.specialFunctionType
        this.TableConfig.tableData[index].specialColorSize = (val.specialFunctionType || '').includes('1')
        this.TableConfig.tableData[index].showSpeial = val.showSpeial
      }

      //获取默认单位的换算比例
      let temp = {
        ...val,
        unitList: val.goodsManyNorms,
        unit: val.defaultUnit,
      };
      this.onHandleUnit(temp, index, false);
    },
    handlePriceChange() {
      // allPrice 总金额
      // receivablePrice 单据金额
      // owePrice 本次欠款

      let zje = delcommafy(this.queryData.allPrice);

      this.queryData.receivablePrice = formatMoney(zje);
      this.queryData.owePrice = formatMoney(zje);
    },
    // 商品总金额变化
    onHandleAllPrice(value) {
      this.queryData.allPrice = value;
      this.handlePriceChange();
    },
    /**
     * 获取当前单据数据
     */
    getOrderData(type) {
      let data = {
        type: "26", //采购订单1/采购入库单2/采购退货单3/采购换货单4/销售订单5/销售出库单6/销售退货单7/销售换货单8/盘点单9/报损单10
        orderFlag: this.orderFlag,
        pageSize: 1,
        pageNo: this.pageNo,
        orderId: this.billId || ''
      };
      getAction(
        "/xghSaleStorehouseOrder/xghSaleStorehouseOrder/preOrNextOrder",
        data
      ).then(
        (res) => {
          this.lowerLoading = false;
          this.upperLoading = false;
          if (res.code === 200) {
            this.pageTotal = res.result.total || 1;
            this.pageNo = res.result.current
            let list = res.result.records || [];
            if (list.length) {
              // 处理请求到的数据
              this.handleData(list[0]);
            } else {
              if (type == 0) {
                this.$elMessage.warning("已经是第一条了");
              } else {
                this.$elMessage.warning("已经是最后一条了");
              }
            }
          } else if (res.code === 500) {
            this.showTips(res.message);
          }
        },
        (error) => {
          this.lowerLoading = false;
          this.upperLoading = false;
        }
      );
    },
    getCompanyInfo() {
      // 调用供应商详情接口，把单据对应的供应商存储到历史记录缓存中
      getAction("/xgh/company/queryById", {
        id: this.queryData.xghCompanyId,
      }).then((res) => {
        if (res.code === 200) {
          this.onSelectSupplier(res.result);
        }
      });
    },
    // 处理请求到的数据
    handleData(res) {
      console.log("handleData");
      let orderObj = res.saleStorehouseOrderPage;

      //公用信息
      this.billId = orderObj.id;
      this.orderStatus = orderObj.orderStatus;
      this.logData.orderId = orderObj.id;

      //单据信息
      this.queryData = {
        ...orderObj,
        orderDiscountPrice: formatMoney(orderObj.orderDiscountPrice),
        receivablePrice: formatMoney(orderObj.receivablePrice),
        owePrice: formatMoney(orderObj.owePrice),
        collectionPrice: formatMoney(orderObj.collectionPrice),
        allPrice: formatMoney(orderObj.allPrice),
        isSupplement: orderObj.isReplacementOrder == "1" ? false : true, //是否补单-0：是 1:不是
        expressStatus: orderObj.expressStatus == "1" ? false : true, //物流状态-0：开启 1:关闭
        expressPayStatus: orderObj.expressPayStatus == "1" ? true : false, //物流费付款状态1：已付款，2：未付
        orderRebate: orderObj.orderRebate + "",
      };

      //商品明细
      const newTableList = orderObj.xghSaleStorehouseOrderInfoList;
      newTableList.forEach((item) => {
        item.isGive = item.isGift == "0" ? true : false; //赠品0:是赠品1：不是赠品
        item.numberShow = formatNumber(item.number);
        item.salePriceShow = formatPrice(item.salePrice);
        item.allPriceShow = formatMoney(item.allPrice);
        item.goodsName = item.goodsName ? item.goodsName : item.goodsId_dictText;
        item.compulsory = "0";
        item.unitList = item.goodsManyNorms

        // 特殊功能
        item.specialColorSize = (item.specialFunctionType || '').includes('1')
        item.showSpeial = true
        item.mainId = this.queryData.orderNumber
        item.attributeOrderInfoRequest = getAttributeOrderInfoRequest(item.attributeGoodsResponse)
      });
      // 增加字段数据，避免不能更新页面
      this.TableConfig.tableData = JSON.parse(JSON.stringify(newTableList));
      // 处理打印数据
      this.$nextTick(() => {
        // 添加打印数据
        this.printData = {
          ...this.queryData,
          xghCompanyId_dictText: orderObj.xghCompanyId_dictText,
          xghOutStorehouseId_dictText: orderObj.xghOutStorehouseId_dictText,
          sysUserId_dictText: orderObj.sysUserId_dictText,
          xghOutType_dictText: this.$refs.xghOutTypeSelect.selected.label,
          xghOutDeptId_dictText: this.$refs.xghOutDeptSelect.selected.label,
          printExclusive: this.TableConfig.tableData,
        };
      });
      // 保存原数据
      this.saveData = JSON.parse(
        JSON.stringify({
          ...this.queryData,
          ...this.TableConfig.tableData,
        })
      );
    },
    /**
     * 选择仓库数据
     */
    onChangeCk() {
      let result = false;
      for (let index = 0; index < this.TableConfig.tableData.length; index++) {
        const element = this.TableConfig.tableData[index];
        if (element.goodsId) {
          result = true;
          break;
        }
      }
      if (result) {
        this.tipsData.tipsWords = "是否更新单据明细中的仓库？";
        this.tipsData.tipsMark = "onChangeCk";
        this.$refs.reminderRef.dialogVisible = true;
      } else if (
        this.TableConfig.tableData.length == 1 &&
        !this.TableConfig.tableData[0].goodsId
      ) {
        this.TableConfig.tableData[0].xghStorehouseId = this.queryData.xghOutStorehouseId;
      }
    },

    // 打开新增仓库的弹框
    onShowWhAdd() {
      this.$refs.warehouseAddRef.dialogVisible = true;
    },
    // 新增仓库数据
    async onAddWh(val) {
      val.isMain = val.isMain == true ? 1 : 0;
      const res = await postAction("/xghStorehouse/xghStorehouse/add", val);
      if (res.code == 200) {
        this.$elMessage.success(res.message);
        this.getWarehouseData();
      } else {
        this.$elMessage.error(res.message);
      }
    },
    // 关闭新增仓库时清空
    onCloseAddWh() {
      this.newWhData = this.$options.data().newWhData;
    },
    hongchongSure() {
      // 红冲
      this.updateOrder(20);
    },
    // 其他出库单审核
    updateOrder(state) {
      getAction("/xghSaleStorehouseOrder/xghSaleStorehouseOrder/changeStatus", {
        id: this.billId,
        code: state,
        negativeInventory: this.negativeInventory ? "1" : "0",
      }).then((res) => {
        if (res.code === 200) {
          this.orderStatus = state;
          this.queryData.orderStatus_dictText = this.getOrderStatusText(state);
          this.$refs.simplePrompt.show({
            index: 0,
            text: this.getMessageByChangeOrderStatus(state),
          });
          if (state == 5) {
            this.afterExamine();
          }
        } else if (res.code == 48) {
          let config = sysConfig();
          let show = false;
          let name = "";
          if (config.allow_negative_inventory) {
            // 允许负库存
            show = true;
            name = `商品${res.message}库存不足, 是否继续审核?`;
          } else {
            show = false;
            name = `商品${res.message}库存不足, 并且不允许负库存, 无法进行审核!`;
          }
          this.showNegativeInventoryDialog = true;
          let item = {
            id: "",
            name: name,
            index: 2,
            show: show,
          };
          this.negativeInventoryData = item;
        } else if (res.code == 49) {
           // 红冲 负库存 提醒
           let show = true
          let name = `商品${res.message}库存不足, 是否继续红冲?`
          this.showNegativeInventoryDialog = true
          let item = {
            id: '',
            name: name,
            index: 3,
            show: show,
          }
          this.negativeInventoryData = item
        } else {
          this.showTips(res.message);
        }
      });
    },
    getOrderStatusText(os) {
      let object = {
        0: "待审核",
        5: "已审核",
        10: "已作废",
        15: "待审核",
        20: "已红冲",
        25: "已终止",
        30: "已完成",
      };
      return object[os + ""];
    },
    getMessageByChangeOrderStatus(os) {
      let object = {
        5: "单据审核成功",
        10: "单据作废成功",
        15: "单据反审成功",
        20: "单据红冲成功",
        25: "单据终止成功",
        30: "单据已完成",
      };
      return object[os + ""];
    },
    // 根据出货仓库选择商品里的仓库
    // force是否强制更新，true 用户选择不更新单据详情时 为空的强制赋值，false 选择更新单据 全部覆盖
    getXghStorehouseIdById(force) {
      this.TableConfig.tableData.forEach((item) => {
        if (force) {
          if (!item.xghStorehouseId) {
            item.xghStorehouseId = this.queryData.xghOutStorehouseId;
          }
        } else {
          item.xghStorehouseId = this.queryData.xghOutStorehouseId;
        }
      });
    },
    // 上一条
    onUpper() {
      if (this.orderStatus == 66 && this.getHaveChange()) {
        this.tipsData.tipsWords = "当前单据还未保存，</br>是否继续？";
        this.tipsData.tipsMark = "onUpper";
        this.$refs.reminderRef.dialogVisible = true;
      } else {
        this.switchoverBill(1);
      }
    },
    // 下一条
    onLower() {
      if (this.orderStatus == 66 && this.getHaveChange()) {
        this.tipsData.tipsWords = "当前单据还未保存，</br>是否继续？";
        this.tipsData.tipsMark = "onLower";
        this.$refs.reminderRef.dialogVisible = true;
      } else {
        this.switchoverBill(2);
      }
    },
    switchoverBill(flag) {
      if (this.orderFlag === 0) {
        this.orderFlag = flag;
      }
      if (flag === 1) {
        if (
          this.pageTotal === 0 ||
          (this.orderFlag === 1 && this.pageNo === this.pageTotal) ||
          (this.orderFlag === 2 && this.pageNo === 1)
        ) {
          this.$elMessage.warning("已经是第一条了");
          return;
        }
        let value = this.orderFlag === 1 ? 1 : -1;
        this.pageNo += value;
        this.upperLoading = true;
        this.getOrderData("0");
      } else if (flag === 2) {
        if (
          this.pageTotal === 0 ||
          (this.orderFlag === 1 && this.pageNo === 1) ||
          (this.orderFlag === 2 && this.pageNo === this.pageTotal)
        ) {
          this.$elMessage.warning("已经是最后一条了");
          return;
        }
        let value = this.orderFlag === 1 ? -1 : 1;
        this.pageNo += value;
        this.lowerLoading = true;
        this.getOrderData("1");
      }
    },
    // 打开列配置弹框
    onShowColumn() {
      this.defaultColumnData = handleObjectToArray(
        this.$options.data().TableConfig.columnData
      );
      this.$refs.setColumnRef.dialogVisible = true;
    },

    // 打开新增经手人的弹框
    onShowStaffAdd() {
      this.$refs.staffAddRef.dialogVisible = true;
    },
    // 打开新增出库类型的弹窗
    onShowOutTypeAdd() {
      this.dialogVisible = true;
      this.inOrOut = 2;
      this.dialogTitle = "其他出库类型设置";
    },
    // 获取新增经手人数据
    onAddStaff(val) {
      postAction("/dept/xghAccountBookDept/addAccountBookUser", val).then((res) => {
        if (res.code === 200) {
          this.$elMessage.success(res.message);
          this.$refs.staffAddRef.dialogVisible = false;
          this.getStaffData();
        } else {
          this.$elMessage.error(res.message);
        }
      });
    },
    // 关闭新增员工时清空
    onCloseAddStaff() {},
    // 打开新增客户弹出框
    onShowSupplierAdd() {
      this.$refs.supplierAddRef.dialogVisible = true;
    },
    // 新增客户数据
    onAddSupplier(res) {
      this.getGysStorage();
    },
    // 关闭新增供应商弹框
    onCloseAddSupplier() {},
    // 打开选择客户弹出框
    onShowSupplier() {
      this.$refs.supplierRef.dialogVisible = true;
    },
    // 当前选择客户数据
    onSelectSupplier(val) {
      this.queryData.xghCompanyId = val.id;
      this.companyName = val.companyName;
    },
    // 下拉选择往来单位
    onChangeCompany(val) {
      this.companyName = this.gysOptions.find((item) => item.id === val).companyName;
    },
    // 历史记录数据去重并只展示三个数据方法
    selectDataHas(arr) {
      let map = new Map();
      for (const item of arr) {
        if (!map.has(item.id)) {
          map.set(item.id, item);
        }
      }
      let newArr = [...map.values()];
      return newArr.slice(0, 3);
    },
    // 打开操作日志弹框
    onShowLog() {
      this.$refs.operationLogRef.getData(this.logData);
      this.logTitle = "单据操作日志";
      this.$refs.operationLogRef.dialogVisible = true;
    },
    // 判断是否有反审权限
    async checkReVerifyPermission() {
      let accountBook = Vue.ls.get(ACCOUNT_BOOK);
      let accountId = accountBook && accountBook.id;
      var res = await getAction("/sysConfig/systemConfig/checkReVerifyPermission", {
        xghAccountBookId: accountId,
      });
      if (res.success) {
        this.onUnToExamine()
      } else {
        this.$refs.deApprovalRef.dialogVisible = true;
      }
    },
    onUnToExamine() {
      getAction("/xghSaleStorehouseOrder/xghSaleStorehouseOrder/changeStatus", {
        id: this.billId,
        code: 15,
      }).then((res) => {
        if (res.code === 200) {
          this.orderStatus = 0
          this.queryData.orderStatus = 0
          this.queryData.orderStatus_dictText = this.getOrderStatusText(0)
          this.saveData.orderStatus = 0
          this.saveData.orderStatus_dictText = this.getOrderStatusText(0)
          this.$refs.simplePrompt.show({
            index: 0,
            text: "单据反审成功",
          });
        } else if (res.code === 500) {
          this.showTips(res.message);
        }
      });
    },
    // 搜索
    handleFilterMethod(value, label) {
      if (label == "companyName") {
        this.gysOptions = this.filterMethod(this.gysOptions, value, label);
      } else if (label == "storehouseName") {
        this.ckOptions = this.filterMethod(this.ckOptions, value, label);
      } else if (label == "realname") {
        this.jsrOptions = this.filterMethod(this.jsrOptions, value, label);
      }
    },
    // 键盘enter键处理
    // 客户
    handleCompanyEnter() {
      if (!this.queryData.xghCompanyId) {
        this.onShowSupplierAdd()
      }
    },
    // 仓库
    handleStoreEnter() {
      if (!this.queryData.xghOutStorehouseId) {
        this.onShowWhAdd()
      }
    },
    // 经手人
    handleUserEnter() {
      if (!this.queryData.xghUserId) {
        this.onShowStaffAdd()
      }
    },
    // 出库类型
    handleOutTypeEnter() {
      if (!this.queryData.xghOutTypeId) {
        this.onShowOutTypeAdd()
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.el-select-dropdown {
  .el-scrollbar__view {
    max-height: 250px;
    overflow: auto;

    .add_select {
      &:last-of-type {
        margin-bottom: 40px;
      }
    }

    .last_li {
      position: absolute;
      bottom: 0px;
      width: 100%;
      height: 40px;
      background: #fff;
      line-height: 40px;
      font-size: 14px;
      color: #0089ff;
      cursor: pointer;
    }
  }
}

.basic_info {
  width: 100%;
  height: 100%;
  background: #f0f2f5;
  box-sizing: border-box;
  padding: 0 10px;
  display: flex;
  flex-direction: column;
}

.info_operation_btn {
  width: 100%;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: PingFang SC;
  font-size: 12px;
  ::v-deep .el-button {
    text-align: center;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    border-radius: 0.093756rem;
    border: none;
    margin-right: 0.1rem;
    margin-left: 0;
    padding: 9px 0.2rem;
  }

  // .el-button--default {
  //   color: #666;
  // }

  ::v-deep .el-select {
    height: 30px;
    box-sizing: border-box;
    margin-right: 10px;

    .el-input {
      height: 100%;

      .el-input__inner {
        width: 70px;
        height: 100%;
        border: none;
        font-size: 12px;
      }

      .el-input__suffix {
        height: 100%;
        display: flex;
        align-items: center;
      }

      .el-textarea {
        height: 100%;
        width: 30px;
      }
    }
  }

  ::v-deep .el-checkbox {
    display: flex;
    align-items: center;
    margin-left: 10px;

    .el-checkbox__input {
      height: 19px;
      display: flex;
      align-items: center;
    }

    .el-checkbox__label {
      font-size: 12px;
      padding-left: 5px;
      color: #666;
    }

    .is-checked {
      .el-checkbox__inner {
        background: #1a93fa;
        border-color: #1a93fa;
      }
    }
  }

  .arrow_btn {
    width: 30px;
    height: 30px;
    background: #ffffff;
    padding: 0;
    margin-right: 0;
  }

  p {
    font-size: 12px;
    color: #666;
    margin-right: 0.25rem;
  }

  .search_order {
    display: flex;
    align-items: center;
    margin-left: 10px;

    p {
      margin-right: 0;
    }
  }

  .btn_left {
    height: 100%;
    display: flex;
    justify-content: flex-start;
    align-items: center;
  }

  .btn_right {
    height: 100%;
    display: flex;
    justify-content: flex-end;
    align-items: center;
  }
}

.info_content_div {
  width: 100%;
  height: calc(100% - 50px);
  background: #fff;
  box-sizing: border-box;
  padding: 0 0.168761rem;
  display: flex;

  .div_table {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;

    .div_screen {
      width: 100%;
      padding: 10px 0;
      display: flex;
      justify-content: space-between;
      align-items: center;

      ::v-deep .el-select {
        height: 30px;
        box-sizing: border-box;
        margin-right: 10px;

        .el-input {
          height: 100%;

          .el-input__inner {
            height: 100%;
            font-size: 12px;
          }

          .el-input__suffix {
            height: 100%;
            display: flex;
            align-items: center;
          }

          .el-textarea {
            height: 100%;
            width: 30px;
          }
        }
      }

      ::v-deep .el-date-editor {
        width: 120px;
        height: 30px;

        .el-input__inner {
          width: 100%;
          height: 30px;
          padding: 0 0.187512rem;
          font-size: 12px;
          color: #666;
        }

        .el-input__prefix {
          left: unset;
          right: 5px !important;

          .el-input__icon {
            line-height: 30px;
            font-size: 16px;
          }
        }

        .el-input__suffix {
          display: none;
        }
      }

      .screen_right {
        width: 30px;
        height: 100%;
        padding-top: 10px;

        .set_up {
          line-height: 20px;
          font-size: 20px;
          color: rgb(153, 153, 153);
        }
      }
    }

    .table_content {
      flex: 1;
      margin-top: 10px;
      box-sizing: border-box;
      overflow: auto;

      > div {
        width: 100%;
        height: 100%;
        border: 1px solid #e3e3e3;
      }
    }
  }
}

.table_item {
  display: flex;
  align-items: center;
  font-size: 12px;
  div {
    width: 50px;
  }

  ::v-deep .el-input {
    flex: 1;
    height: 30px;

    .el-input__inner {
      height: 100%;
      padding: 0 5px;
      font-size: 12px;
      color: #666;
    }
  }
}
</style>
